package servlet;

import dao.GoodsDao;
import pojo.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.print.Book;
import java.io.IOException;
import java.util.List;

/**
 * @author konley
 * @date 2020-06-20 11:13
 */
@WebServlet("/FindGoodsServlet")
public class FindGoodsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String m = request.getParameter("m");
        System.out.println("findGoods m = " + m);
        if(m!=null){   //从下拉列表点击，精确查找
            String comm = request.getParameter("name");
            System.out.println("comm = " + comm);
            List<Goods> list = new GoodsDao().getListByName(comm);
            request.setAttribute("list", list);
            request.getRequestDispatcher("/managerView.jsp").forward(request,response);
        }else{ //点击按钮 没有m值
            String comm = request.getParameter("comm");
            List<Goods> list = new GoodsDao().getListByName(comm);
            request.setAttribute("list", list);
            request.getRequestDispatcher("/managerView.jsp").forward(request,response);
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
